/*
 * Copyright (c) 2011, Michael van der Westhuizen
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *    - Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *    - Redistributions in binary form must reproduce the above
 *      copyright notice, this list of conditions and the following
 *      disclaimer in the documentation and/or other materials provided
 *      with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
#ifndef PYXMLSEC1_XMLSEC_H_MCVDW_20101121
#define PYXMLSEC1_XMLSEC_H_MCVDW_20101121

#include <Python.h>

#include <xmlsec/xmlsec.h>
#include <xmlsec/base64.h>
#include <xmlsec/bn.h>
#include <xmlsec/keysmngr.h>
#include <xmlsec/dl.h>

#include <libxml/xpath.h>

#include <string.h>

#define XMLSEC1_XMLSECBASE64CTXPTRNAME "xmlSecBase64CtxPtr"
#define XMLSEC1_XMLSECBNPTRNAME "xmlSecBnPtr"
#define XMLSEC1_XMLSECBUFFERPTRNAME "xmlSecBufferPtr"
#define XMLSEC1_XMLSECKEYSMNGRPTRNAME "xmlSecKeysMngrPtr"
#define XMLSEC1_XMLSECKEYSTOREPTRNAME "xmlSecKeyStorePtr"
#define XMLSEC1_XMLSECKEYSTOREIDNAME "xmlSecKeyStoreId"
#define XMLSEC1_XMLSECPTRLISTPTRNAME "xmlSecPtrListPtr"
#define XMLSEC1_XMLSECPTRLISTIDNAME "xmlSecPtrListId"
#define XMLSEC1_XMLSECTRANSFORMIDNAME "xmlSecTransformId"
#define XMLSEC1_XMLSECTRANSFORMPTRNAME "xmlSecTransformPtr"
#define XMLSEC1_XMLSECTRANSFORMCTXPTRNAME "xmlSecTransformCtxPtr"
#define XMLSEC1_XMLSECNODESETPTRNAME "xmlSecNodeSetPtr"
#define XMLSEC1_XMLSECKEYPTRNAME "xmlSecKeyPtr"
#define XMLSEC1_XMLSECKEYREQPTRNAME "xmlSecKeyReqPtr"
#define XMLSEC1_XMLSECKEYINFOCTXPTRNAME "xmlSecKeyInfoCtxPtr"
#define XMLSEC1_XMLSECKEYDATASTOREPTRNAME "xmlSecKeyDataStorePtr"
#define XMLSEC1_XMLSECKEYDATASTOREIDNAME "xmlSecKeyDataStoreId"
#define XMLSEC1_XMLSECKEYDATAIDNAME "xmlSecKeyDataId"
#define XMLSEC1_XMLSECKEYDATAPTRNAME "xmlSecKeyDataPtr"
#define XMLSEC1_XMLSECKEYUSEWITHPTRNAME "xmlSecKeyUseWithPtr"
#define XMLSEC1_XMLSECDSIGCTXPTRNAME "xmlSecDSigCtxPtr"
#define XMLSEC1_XMLSECCRYPTODLFUNCTIONSPTRNAME "xmlSecCryptoDLFunctionsPtr"

int xmlsec1_ByteArrayOrBytesToXmlSecBytes(PyObject * in, xmlSecByte ** out, xmlSecSize * outSize);
int xmlsec1_UnicodeOrBytesToXmlCharPtr(PyObject * in, xmlChar ** out, int * outSize);
xmlNodeSetPtr xmlsec1mod_SequenceToXmlNodeSetPtr(PyObject * obj);
PyObject * xmlsec1mod_xmlNodeSetPtrToList(xmlNodeSetPtr ptr);

PyObject * xmlsec1mod_wrap_xmlSecBase64CtxPtr(xmlSecBase64CtxPtr ptr);
xmlSecBase64CtxPtr xmlsec1mod_unwrap_xmlSecBase64CtxPtr(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecBnPtr(xmlSecBnPtr ptr);
xmlSecBnPtr xmlsec1mod_unwrap_xmlSecBnPtr(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecBufferPtr(xmlSecBufferPtr ptr);
xmlSecBufferPtr xmlsec1mod_unwrap_xmlSecBufferPtr(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecKeysMngrPtr(xmlSecKeysMngrPtr ptr);
xmlSecKeysMngrPtr xmlsec1mod_unwrap_xmlSecKeysMngrPtr(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecKeyStorePtr(xmlSecKeyStorePtr ptr);
xmlSecKeyStorePtr xmlsec1mod_unwrap_xmlSecKeyStorePtr(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecKeyStoreId(xmlSecKeyStoreId ptr);
xmlSecKeyStoreId xmlsec1mod_unwrap_xmlSecKeyStoreId(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecPtrListPtr(xmlSecPtrListPtr ptr);
xmlSecPtrListPtr xmlsec1mod_unwrap_xmlSecPtrListPtr(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecPtrListId(xmlSecPtrListId ptr);
xmlSecPtrListId xmlsec1mod_unwrap_xmlSecPtrListId(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecTransformId(xmlSecTransformId ptr);
xmlSecTransformId xmlsec1mod_unwrap_xmlSecTransformId(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecTransformPtr(xmlSecTransformPtr ptr);
xmlSecTransformPtr xmlsec1mod_unwrap_xmlSecTransformPtr(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecTransformCtxPtr(xmlSecTransformCtxPtr ptr);
xmlSecTransformCtxPtr xmlsec1mod_unwrap_xmlSecTransformCtxPtr(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecNodeSetPtr(xmlSecNodeSetPtr ptr);
xmlSecNodeSetPtr xmlsec1mod_unwrap_xmlSecNodeSetPtr(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecKeyPtr(xmlSecKeyPtr ptr);
xmlSecKeyPtr xmlsec1mod_unwrap_xmlSecKeyPtr(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecKeyReqPtr(xmlSecKeyReqPtr ptr);
xmlSecKeyReqPtr xmlsec1mod_unwrap_xmlSecKeyReqPtr(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecKeyInfoCtxPtr(xmlSecKeyInfoCtxPtr ptr);
xmlSecKeyInfoCtxPtr xmlsec1mod_unwrap_xmlSecKeyInfoCtxPtr(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecKeyDataStorePtr(xmlSecKeyDataStorePtr ptr);
xmlSecKeyDataStorePtr xmlsec1mod_unwrap_xmlSecKeyDataStorePtr(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecKeyDataStoreId(xmlSecKeyDataStoreId ptr);
xmlSecKeyDataStoreId xmlsec1mod_unwrap_xmlSecKeyDataStoreId(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecKeyDataId(xmlSecKeyDataId ptr);
xmlSecKeyDataId xmlsec1mod_unwrap_xmlSecKeyDataId(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecKeyDataPtr(xmlSecKeyDataPtr ptr);
xmlSecKeyDataPtr xmlsec1mod_unwrap_xmlSecKeyDataPtr(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecKeyUseWithPtr(xmlSecKeyUseWithPtr ptr);
xmlSecKeyUseWithPtr xmlsec1mod_unwrap_xmlSecKeyUseWithPtr(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecDSigCtxPtr(xmlSecDSigCtxPtr ptr);
xmlSecDSigCtxPtr xmlsec1mod_unwrap_xmlSecDSigCtxPtr(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlSecCryptoDLFunctionsPtr(xmlSecCryptoDLFunctionsPtr ptr);
xmlSecCryptoDLFunctionsPtr xmlsec1mod_unwrap_xmlSecCryptoDLFunctionsPtr(PyObject * obj);

PyObject * xmlsec1mod_wrap_xmlDocPtr(xmlDocPtr ptr);
xmlDocPtr xmlsec1mod_unwrap_xmlDocPtr(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlNodePtr(xmlNodePtr ptr);
xmlNodePtr xmlsec1mod_unwrap_xmlNodePtr(PyObject * obj);
xmlNodeSetPtr xmlsec1mod_unwrap_xmlNodeSetPtr(PyObject * obj);
xmlOutputBufferPtr xmlsec1mod_unwrap_xmlOutputBufferPtr(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlOutputBufferPtr(xmlOutputBufferPtr ptr);
xmlParserInputBufferPtr xmlsec1mod_unwrap_xmlParserInputBufferPtr(PyObject * obj);
PyObject * xmlsec1mod_wrap_xmlParserInputBufferPtr(xmlParserInputBufferPtr ptr);

#define ENSURE_EXCEPTION_SET(x) do { \
    if (!PyErr_Occurred()) { \
        PyErr_SetString(PyExc_RuntimeError, #x " failed"); \
    } \
} while(0)

#endif
